package h0824;

import java.util.HashMap;
/**
  * @description 两数之和
  * @author 不知名帅哥
  * @date 2024/8/24 18:14
  * @version 1.0
*/
public class TwoSum {
    public static void main(String[] args) {
        int[] nums=new int[]{3,2,4};
        twoSum(nums,6);
    }
    public static int[] twoSum(int[] nums, int target) {
        HashMap<Integer, Integer> map = new HashMap<>();

        for (int i = 0; i < nums.length; i++) {
            int temp = target - nums[i];
            if (map.containsKey(temp)){
                return new int[]{map.get(temp),i};
            }
            map.put(nums[i],i);
        }
        return new int[]{0,0};
    }
}
